import React, { Component } from 'react'

export default class CartItem extends Component {
  render() {
    let { index, item, list } = this.props;
    return (
      <div>
        <li key={index}>
          <input type="checkbox" checked={item.checked} onChange={(e) => {
            item.checked = e.target.checked;

            this.props.setList(list);
            console.log('list', list);


          }} />
          <img src={item.img} alt="" />
          <p>{item.title}</p>
          <p>
            {item.price}
          </p>
          <div>
            <button type="primary" onClick={() => {
              if (item.num > 0) {
                item.num--;
              }

              this.props.setList(list);
            }}>-</button>
            {item.num}
            <button type="primary" onClick={() => {
              item.num++;
              this.props.setList(list);
            }}>+</button>
          </div>


        </li>
      </div>
    )
  }
}

